package com.luoying.itew.util;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by octopus on 17/6/23.
 */

public class WeatherUtils {
    private static String Temerture = null;
    private static String Type = null;

    private static String username = null;
    private static String userphone = null;
    private static String userPosition = null;
    private static int userType = 1;

    public static void setWeather(JSONObject jsonObject){
        try {
            JSONObject jsonObject1 = (jsonObject.getJSONObject("resultEntity")).getJSONObject("cityWeather");
            Temerture = jsonObject1.getString("wendu");
            JSONArray jsonArray = jsonObject1.getJSONArray("forecast");
            Type = (((JSONObject) jsonArray.get(0)).getJSONObject("day")).getString("type");
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    public static void setUser(JSONObject jsonObject){
//        try {
//            JSONObject jsonObject1 =  (jsonObject.getJSONObject("resultEntity")).getJSONObject("userDetails");
//            username = jsonObject1.getString("userName");
//            userphone = jsonObject1.getString("userMobile");
//            setDistrict(jsonObject1);
//        } catch (JSONException e) {
//            e.printStackTrace();
//        }

        try {
            JSONObject entity =  (jsonObject.getJSONObject("resultEntity"));
            username = entity.getString("userName");
            userphone = entity.getString("userMobile");
            userPosition = entity.optString("userPosition");
            userType = entity.getInt("userType");
            setDistrict(entity);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    //private static List districtName = new ArrayList();
    //private static List fullName = new ArrayList();
    private static List userAreas = new ArrayList();
    private static String city = null;

    public static void setDistrict(JSONObject jsonObject) throws JSONException{
//        JSONArray jsonArray = jsonObject.getJSONArray("userStreet");
//        city = ((JSONObject)jsonArray.get(0)).getString("cityName");
//        for(int i=0;i<jsonArray.length();i++) {
//            JSONObject user = null;
//            user = (JSONObject) jsonArray.get(i);
//            districtName.add(user.getString("districtName"));
//            fullName.add(user.getString("fullName"));
//        }


        city = jsonObject.getString("userCity");
        //city = ((JSONObject)jsonArray.get(0)).getString("cityName");
        JSONArray array = jsonObject.getJSONArray("userAreas");
        for(int i=0; i< array.length();i++) {
            JSONObject userArea = (JSONObject) array.get(i);
            userAreas.add(userArea.getString("areaName"));
            //districtName.add(user.getString("districtName"));
            //fullName.add(user.getString("fullName"));
        }
    }


    public static String getTemerture() {
        return Temerture;
    }

    public static String getType() {
        return Type;
    }

    public static String getCity() {
        return city;
    }

    public static String getUsername() {
        return username;
    }

    public static String getUserphone() {
        return userphone;
    }

    public static String getUserPosition() {
        return userPosition;
    }

    public static List getUserAreas() {
        return userAreas;
    }

    public static int getUserType() {
        return userType;
    }

//    public static String getDistrictName(int i){
//        return (String) districtName.get(i);
//    }
//
//    public static int getNumber(){
//        return districtName.size();
//    }
}
